package net.htjs.juc.countdownlatch;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

@Slf4j
public class Demo1 {


    public static void main(String[] args) throws InterruptedException {
        int threadCount = 3;
        CountDownLatch latch = new CountDownLatch(threadCount);

        for (int i = 0; i < threadCount; i++) {
            new Thread(() -> {
                log.info("{} 执行任务", Thread.currentThread().getName() );
                latch.countDown(); // 任务完成，计数器减1
            }).start();
        }

        latch.await(); // 主线程等待所有子线程完成任务
        log.info("所有线程任务已完成，继续主线程");
    }


}
